#include "cAABB.h"

cOverlapTest::cOverlapTest() : distance(0.0f)
{
}

float cOverlapTest::distanceTo(Vector3D point1, Vector3D point2)
{
	//Zeroes out the distance before calculation
	if(distance > 0.0f)
		distance = 0.0f;

	//Stores the magnitude of each point into a temporary
	//variable for distance calculation
	float magnitude1 = point1.Magnitude();
	float magnitude2 = point2.Magnitude();

	//Calculates the distance using the distance formula
	distance = abs(sqrt((magnitude2 * magnitude2) - (magnitude1 * magnitude1)));
	
	if(distance <= 0.001)
		return distance = 0.0f;

	return distance;
}

float cOverlapTest::distanceToSquared(Vector3D point1, Vector3D point2)
{
	if(distance > 0.0f)
		distance = 0.0f;

	//Stores the magnitude of each point into a temporary
	//variable for distance calculation
	float magnitude1 = point1.Magnitude();
	float magnitude2 = point2.Magnitude();

	//Calculates the distance using the distance formula
	distance = abs((magnitude2 * magnitude2) - (magnitude1 * magnitude1));
	
	if(distance <= 0.001)
		return distance = 0.00f;

	return distance;
}

bool cOverlapTest::AABBToAABB(AABB a, AABB b)
{
	if(abs(a.center.getX() - b.center.getX()) > (a.radius.getX() + b.radius.getX()))
		return false;
	
	if(abs(a.center.getY() - b.center.getY()) > (a.radius.getY() + b.radius.getY()))
		return false;

	//if(abs(a.center.getZ() - b.center.getZ()) > (a.radius.getZ() + b.radius.getZ()))
		//return false;

	//If the axis is connecting on all lines
	return true;
}